var Mock = require('mockjs')
var category = require('./category_data.json')
var audience = require('./audience.json')
var industry = require('./industry.json')
var adconvert = require('./adconvert.json')
// console.log(category)
var data = Mock.mock({
  'projects|50': [{
    id: '@id',
    "title": '项目:@increment()', //项目名
    managerid: '', // 负责人ID
    departmentid: '', // 部门ID
    // optimizers: [], // 优化师ID数组
  }],
  'accounts|3000': [{
    id: '@id',
    pid: '',
    title: '账户:@increment()',
    optimizerid: '' // 优化师ID
  }],
  'managers|20': [{
    id: '@id',
    title: '负责人:@increment()'
  }],
  'optimizers|300': [{
    id: '@id',
    title: '优化师:@increment()'
  }],
  'departments|10': [{
    id: '@id',
    title: '部门:@increment()'
  }]
})

function getRandomArrayElements(arr, count) {
    var shuffled = arr.slice(0),
        i = arr.length,
        min = i - count,
        temp, index;
    while (i-- > min) {
        index = Math.floor((i + 1) * Math.random());
        temp = shuffled[index];
        shuffled[index] = shuffled[i];
        shuffled[i] = temp;
    }
    return shuffled.slice(min);
}

var projectCount = data.projects.length
data.accounts.forEach((ele, idx) => {
  // var idx = Math.floor((Math.random() * (projectCount - 1)) + 1);
  ele['pid'] = data.projects[idx % projectCount].id
  var optimizers = getRandomArrayElements(data.optimizers, 1)
  optimizers.forEach(e => {
    ele['optimizerid'] = e.id
  })
})
var managerCount = data.managers.length
var departmentCount = data.departments.length
data.projects.forEach((ele, idx) => {
  ele['managerid'] = data.managers[idx % managerCount].id
  ele['departmentid'] = data.departments[idx % departmentCount].id
})


var datas = [{
        url: '/report/filter',
        type: 'get',
        response: function () {
            return {
                code: 1,
                data: {
                    projects: data.projects,
                    accounts: data.accounts,
                    managers: data.managers,
                    optimizers: data.optimizers,
                    departments: data.departments
                }
            }
        }
    },
    {
        // 首页实时数据
        url: '/project/realdata',
        type: 'get',
        response: function () {
            return {
                code: 1,
                data: {
                    cost: 998,
                    convert: 888,
                    convert_cost: 1028,
                    clue_total: 990,
                    clue_cost: 1999,
                }
            }
        }
    },
    {
        // 首页数据趋势
        url: '/project/chart',
        type: 'get',
        response: function () {
            return {
                code: 1,
                data: {
                    title: {
                        text: ''
                    },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'cross',
                            label: {
                                backgroundColor: '#6a7985'
                            }
                        }
                    },
                    legend: {
                        data: ['邮件营销', '联盟广告']
                    },
                    toolbox: {
                        feature: {
                            saveAsImage: {}
                        }
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: [{
                        type: 'category',
                        boundaryGap: false,
                        data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
                    }],
                    yAxis: [{
                        type: 'value'
                    }],
                    series: [{
                        name: '转化数',
                        type: 'line',
                        stack: '总量',
                        // areaStyle: {},
                        data: [120, 132, 101, 134, 90, 230, 210]
                    },
                    {
                        name: '转化成本',
                        type: 'line',
                        stack: '总量',
                        // areaStyle: {},
                        data: [220, 182, 191, 234, 290, 330, 310]
                    }
                    ]
                }
            }
        }
    },
    // {
    //     url: '/account/list',
    //     type: 'get',
    //     response: function (config) {
    //         console.log(config)
    //         // const items = data.items
    //         return {
    //             code: 1,
    //             data: {
    //                 total: 2,
    //                 items: [{
    //                         id: 10,
    //                         title: '账户A'
    //                     },
    //                     {
    //                         id: 20,
    //                         title: '账户B'
    //                     }
    //                 ]
    //             }
    //         }
    //     }
    // },
    // {
    //     url: '/manager/list',
    //     type: 'get',
    //     response: function (config) {
    //         console.log(config)
    //         // const items = data.items
    //         return {
    //             code: 1,
    //             data: {
    //                 total: 2,
    //                 items: [{
    //                         id: 10,
    //                         title: '管理员A'
    //                     },
    //                     {
    //                         id: 20,
    //                         title: '管理员B'
    //                     }
    //                 ]
    //             }
    //         }
    //     }
    // },
    // {
    //     url: '/optimizer/list',
    //     type: 'get',
    //     response: function (config) {
    //         console.log(config)
    //         // const items = data.items
    //         return {
    //             code: 1,
    //             data: {
    //                 total: 2,
    //                 items: [{
    //                         id: 10,
    //                         title: '优化师A'
    //                     },
    //                     {
    //                         id: 20,
    //                         title: '优化师B'
    //                     }
    //                 ]
    //             }
    //         }
    //     }
    // },
    // {
    //     url: '/department/list',
    //     type: 'get',
    //     response: function (config) {
    //         console.log(config)
    //         // const items = data.items
    //         return {
    //             code: 1,
    //             data: {
    //                 total: 2,
    //                 items: [{
    //                         id: 10,
    //                         title: '部门A'
    //                     },
    //                     {
    //                         id: 20,
    //                         title: '部门B'
    //                     }
    //                 ]
    //             }
    //         }
    //     }
    // },
    {
        url: '/project/data',
        type: 'get',
        response: function () {
            return {
                code: 1,
                data: {
                    total: 3,
                    items: [{
                            id: 1,
                            project: '抖音项目抖音项目抖音项目抖音项目抖音项目',
                            account: '2323@qq.com',
                            manager:'张三',
                            show: '3323',
                            click: '4324',
                            ctr: '50%',
                            convert: '6',
                            convert_cost: '3242',
                            convert_rate: '8%',
                            cost: '323',
                            balance: '5460',
                            note: '备注1',
                            volador_cost:'3211',
                            volador_into:'132'
                        },
                        {
                            id: 2,
                            project: '头条项目',
                            account: 'dsfdf@163.com',
                            manager:'李四',
                            show: '5453',
                            click: '9880',
                            ctr: '40%',
                            convert: '690',
                            convert_cost: '7655',
                            convert_rate: '18%',
                            cost: '7565',
                            balance: '1320',
                            note: '备注2',
                            volador_cost:'5311',
                            volador_into:'232'
                        }
                    ]
                }
            }
        }
    },
    {
        url: '/task/list',
        type: 'get',
        response: function () {
            return {
                code: 1,
                data: {
                    total: 4,
                    items: [{
                            id: 1,
                            project: '抖音项目',
                            depart: '运营2部门',
                            manager: '张三',
                            unfoldshow:false,
                            missions: [{
                                    id: 1,
                                    tast_name: 'xxxxx',
                                    tast_progress:'已完成',
                                    tast_time:'2019-10-20'
                                },
                                {
                                    id: 2,
                                    tast_name: 'aaaaaa',
                                    tast_progress:'进行中',
                                    tast_time:'2019-10-20'
                                }
                            ]
                        },
                        {
                            id: 2,
                            project: '头条项目',
                            depart: '运营1部门',
                            manager: '李四',
                            unfoldshow:false,
                            missions: [{
                                id: 1,
                                tast_name: 'bbbb',
                                tast_progress:'未完成',
                                tast_time:'2019-10-20'
                            }]
                        }
                    ]
                }
            }
        }
    },
    {
        url: '/action/category',
        type: 'get',
        response: function () {
            // action_scene action_days
            return {
                code: 1,
                data: category
            }
        }
    },
    {
        url: '/action/keyword',
        type: 'get',
        response: function () {
            // action_scene action_days
            return {
                code: 1,
                data: {
                    "list": [{
                        "id": 1,
                        "name": "xxxxxx",
                        "num": 100
                    }]
                }
            }
        }
    },
    {
        url: '/custom_audience/select',
        type: 'get',
        response: function () {
            // action_scene action_days
            return {
                code: 1,
                data: audience
            }
        }
    },
    {
        url: '/industry',
        type: 'get',
        response: function () {
            // action_scene action_days
            return {
                code: 1,
                data: industry
            }
        }
    },
    {
        url: '/adconvert',
        type: 'get',
        response: function () {
            // action_scene action_days
            return {
                code: 1,
                data: adconvert
            }
        }
    },
    {
        url: '/actiontext', //行动号召
        type: 'get',
        response: function () {
            // action_scene action_days
            return {
                code: 1,
                data: [
                    "查看详情",
                    "查看详情2"
                ]
            }
        }
    }
]
module.exports = datas